package services

import (
	admindao "TaskAssignmentSystem/internal/admin/dao"
	"TaskAssignmentSystem/internal/pkg/modelbase"
	"TaskAssignmentSystem/pkg/utils"
	"fmt"
)

type SystemNotifyServices struct{}

func (s *SystemNotifyServices) QuerySystemNotifyColumnList() ([]admindao.SystemNotifyColumn, error) {
	var commonServe CommonService[admindao.SystemNotifyColumn]
	if res, err := commonServe.FindAll(); err != nil {
		return nil, err
	} else {
		return res, nil
	}
}

type SystemNotify struct {
	modelbase.SystemNotify
	ColumnName string `json:"column_name"`
}

func (s *SystemNotifyServices) QuerySystemNotifyList(columnId, title string, page, pageSize int64) (int64, []SystemNotify, error) {
	var commonServe CommonService[SystemNotify]
	commonServe.Page = page
	commonServe.PageSize = pageSize

	if utils.StringIsNotEmpty(columnId) {
		commonServe.WhereStr = append(commonServe.WhereStr, fmt.Sprintf("column_id = '%v' ", columnId))
	}
	if utils.StringIsNotEmpty(title) {
		commonServe.WhereStr = append(commonServe.WhereStr, fmt.Sprintf("title like '%%%v%%' ", title))
	}
	field := fmt.Sprintf("tas_system_notify.*,b.name column_name")
	commonServe.SelectField = &field
	commonServe.LeftJoin = append(commonServe.LeftJoin, fmt.Sprintf("LEFT JOIN tas_system_notify_column b on column_id = b.id "))
	commonServe.Order = "sort"
	if res, err := commonServe.SelectList(); err != nil {
		return 0, nil, err
	} else {
		return res.Total, res.Data, nil
	}
}
